package com.hightrast.service.converToClassMapper;

import com.hightrast.service.api.domain.bo.QueryShopifyProduct;
import com.hightrast.service.api.entity.RastProductVariants;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;

@Mapper
public interface ProductVariantMapper {
    ProductVariantMapper INSTANCE = Mappers.getMapper(ProductVariantMapper.class);

    @Mapping(source = "id", target = "id")
    @Mapping(source = "product_id", target = "productId")
    @Mapping(source = "title", target = "title")
    @Mapping(source = "price", target = "price")
    @Mapping(source = "position", target = "position")
    @Mapping(source = "inventory_policy", target = "inventoryPolicy")
    @Mapping(source = "compare_at_price", target = "compareAtPrice")
    @Mapping(source = "option1", target = "option1")
    @Mapping(source = "option2", target = "option2")
    @Mapping(source = "option3", target = "option3")
    @Mapping(source = "created_at", target = "createdAt")
    @Mapping(source = "updated_at", target = "updatedAt")
    @Mapping(source = "taxable", target = "taxable")
    @Mapping(source = "barcode", target = "barcode")
    @Mapping(source = "fulfillment_service", target = "fulfillmentService")
    @Mapping(source = "grams", target = "grams")
    @Mapping(source = "inventory_management", target = "inventoryManagement")
    @Mapping(source = "requires_shipping", target = "requiresShipping")
    @Mapping(source = "sku", target = "sku")
    @Mapping(source = "weight", target = "weight")
    @Mapping(source = "weight_unit", target = "weightUnit")
    @Mapping(source = "inventory_item_id", target = "inventoryItemId")
    @Mapping(source = "inventory_quantity", target = "inventoryQuantity")
    @Mapping(source = "old_inventory_quantity", target = "oldInventoryQuantity")
    @Mapping(source = "image_id", target = "imageId")
    RastProductVariants queryShopifyToProductVariant(QueryShopifyProduct.ProductVariants queryShopifyProduct);

    // 自定义方法：将 OffsetDateTime 转换为 LocalDateTime
    default LocalDateTime convertDateTime(OffsetDateTime offsetDateTime) {
        return offsetDateTime != null ? offsetDateTime.toLocalDateTime() : null;
    }

    // 自定义转换方法：将 Boolean 转换为 Integer
    default Integer convertBoolean(Boolean value) {
        if(value == null){
            return null;
        }
        return value ? 1 : 0;
    }
}